#include "Tree.h"


class Solution {
public:
    void dfs(TreeNode* root, int k, vector<vector<int>>& ans)
    {
       if (root == NULL) return;
       if (k == ans.size()) ans.push_back(vector<int>());
       ans[k].push_back(root->val);
       dfs(root->left, k + 1, ans);
       dfs(root->right, k + 1, ans);
    }
   vector<vector<int>> levelOrderBottom(TreeNode* root) {
       vector<vector<int>> ans;
       dfs(root, 0, ans);
       reverse(ans.begin(), ans.end());
       return ans;
   }
};